/**
 * Project: lionbule-other
 * 
 * File Created at 2012-7-17
 * $Id$
 * 
 * Copyright 1999-2100 Alibaba.com Corporation Limited.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * Alibaba Company. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Alibaba.com.
 */
package com.dm;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;

import org.apache.commons.lang.StringUtils;

/**
 * BuildBlockCodeSql.
 * @author LionBule
 *  2012-7-17 下午4:13:17
 */
public class BuildBlockCodeSql {
    public static void main(String[] args) throws Exception {
        String path = "E:/work/BlockCode迭代四/property_online.data";
        action(path);
        System.out.println("ok");
    }

    static void action(String path) throws Exception {
        FileWriter fw = new FileWriter("E:/work/BlockCode迭代四/property_online.sql");

        FileReader fr = new FileReader(path);
        BufferedReader bf = new BufferedReader(fr);
        String line = null;
        while ((line = bf.readLine()) != null) {
            String[] t = StringUtils.splitPreserveAllTokens(line, ",");
            String id = t[0].trim();
            String parentId = t[1].trim();
            String code = t[2].trim();
            String type = t[3].trim();
            String status = t[4].trim();
            String dw_table = t[5].trim();
            String dw_column = t[6].trim();
            String sql = getSql(id, parentId, code, type, status, dw_table, dw_column);
            fw.write(sql);
        }
        bf.close();
        fw.close();
    }

    static String getSql(String id, String parentId, String code, String type, String status,
                         String dw_table, String dw_column) {
        StringBuilder sb = new StringBuilder();
        sb.append(
                "insert into agds_dm_property (id, path_id,pcode,pname,data_type,status,dw_table,dw_column,creater,operator,gmt_create,gmt_modified)")
                .append(" values (").append(id).append(",").append(parentId).append(",'")
                .append(code).append("','").append(code).append("',").append(type).append(",")
                .append(status).append(",'").append(dw_table).append("','").append(dw_column)
                .append("','qingyan.maqy','qingyan.maqy',now(),now()").append(");\n");
        return sb.toString();
    }

}
